package com.kly.cashmall.base.app_action;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

/**
 * Created by
 * on 2019/5/6.
 */
public class ActionBuildHelper {
    private String host;
    private HashMap<String, String> paramsMap;

    private ActionBuildHelper(String action) {
        ActionParams params = ActionParams.parse(action);
        this.paramsMap = params.getParamsMap();
        this.host = params.getAction();
    }

    public static ActionBuildHelper with(String action) {
        return new ActionBuildHelper(action);
    }

    public ActionBuildHelper put(String key, String value) {
        this.paramsMap.put(key, value);
        return this;
    }

    public String getAction() {
        StringBuilder appendText = new StringBuilder();
        Iterator var2 = this.paramsMap.entrySet().iterator();

        while(var2.hasNext()) {
            Map.Entry<String, String> entry = (Map.Entry)var2.next();
            appendText.append(appendText.length() == 0 ? "" : "&").append((String)entry.getKey()).append("=").append((String)entry.getValue());
        }

        return this.host + (appendText.length() == 0 ? "" : "?" + appendText.toString());
    }
}
